package com.github.caijh.mall.store.service.impl;

import java.util.List;
import javax.annotation.Resource;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.caijh.mall.common.PageParams;
import com.github.caijh.mall.store.dao.StoreProductCateDao;
import com.github.caijh.mall.store.model.StoreProductCate;
import com.github.caijh.mall.store.request.StoreProductCateSearchReqBody;
import com.github.caijh.mall.store.service.StoreProductCateService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

@Service
public class StoreProductCateServiceImpl extends ServiceImpl<StoreProductCateDao, StoreProductCate>
        implements StoreProductCateService {

    @Resource
    private StoreProductCateDao dao;


    /**
     * 列表
     *
     * @param request    请求参数
     * @param pageParams 分页类参数
     * @return {@code List<StoreProductCate>}
     * @author Mr.Zhang
     * @since 2020-05-27
     */
    @Override
    public List<StoreProductCate> getList(StoreProductCateSearchReqBody request, PageParams pageParams) {
        PageHelper.startPage(pageParams.getPage(), pageParams.getLimit());

        //带 StoreProductCate 类的多条件查询
        LambdaQueryWrapper<StoreProductCate> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        StoreProductCate model = new StoreProductCate();
        BeanUtils.copyProperties(request, model);
        lambdaQueryWrapper.setEntity(model);
        return dao.selectList(lambdaQueryWrapper);
    }

    @Override
    public List<StoreProductCate> getByProductId(Integer productId) {
        LambdaQueryWrapper<StoreProductCate> lqw = new LambdaQueryWrapper<>();
        lqw.eq(StoreProductCate::getProductId, productId);
        return dao.selectList(lqw);
    }

}

